package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusCarPackageAudit;
import cn.wolfcode.business.domain.vo.CarPackageAuditIVO;
import cn.wolfcode.business.domain.vo.HistoryVo;
import cn.wolfcode.business.service.IBusCarPackageAuditService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.filter.RequestContextFilter;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("/business/audit")
public class BusCarPackageAuditController extends BaseController {
    @Autowired
    private IBusCarPackageAuditService busCarPackageAuditService;
    @Autowired
    private RequestContextFilter requestContextFilter;

    @GetMapping("/list")
    public TableDataInfo list(BusCarPackageAudit busCarPackageAudit){
        startPage();
        List<BusCarPackageAudit> list = busCarPackageAuditService.selectBusCarPackageAuditList(busCarPackageAudit);
        return getDataTable(list);
    }

    @GetMapping("/processImg/{instanceId}")
    public void processImg(@PathVariable Long instanceId, HttpServletResponse resp) throws IOException {
        InputStream inputStream =  busCarPackageAuditService.processImg(instanceId);
        IOUtils.copy(inputStream,resp.getOutputStream());
    }
    @DeleteMapping(value = "/{id}",headers = "cmd=processCancel")
    public AjaxResult remove(@PathVariable Long id){
        return toAjax(busCarPackageAuditService.deleteBusCarPackageAuditById(id));
    }

    @GetMapping("/historyList")
    public AjaxResult historyList(Long instanceId){
        List<HistoryVo> list = busCarPackageAuditService.selectHistoryList(instanceId);
        return AjaxResult.success(list);
    }

    @GetMapping("/todoTaskList")
    public TableDataInfo todoTaskList(BusCarPackageAudit busCarPackageAudit){
        List<BusCarPackageAudit> list = busCarPackageAuditService.selecttodoTaskList(busCarPackageAudit);
        return getDataTable(list);
    }

    @PatchMapping(headers = "cmd=audit")
    public AjaxResult audit(@RequestBody CarPackageAuditIVO carPackageAuditIVO){
        return toAjax(busCarPackageAuditService.audit(carPackageAuditIVO));
    }
    @GetMapping("/DoneTask")
    public TableDataInfo DoneTask(BusCarPackageAudit busCarPackageAudit){
        List<BusCarPackageAudit> list = busCarPackageAuditService.selectDoneTask(busCarPackageAudit);
        return getDataTable(list);
    }
}
